/*
 * Copyright 2007 National Bioinformatics Network
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * 
 */
package dgbgui.actions;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractAction;

/**
 * @author bjnortier
 *
 */
public class ActionGroup {
	
	// ---------- Constructors ----------

	public ActionGroup(String name, ArrayList<Object> actionsOrGroups) {
		m_name = name;
		m_actionsOrGroups = actionsOrGroups;
		// All object must be actions or groups
		for ( Object ob : actionsOrGroups) {
			assert ((ob instanceof AbstractAction) || (ob instanceof ActionGroup));
		}
	}
	
	public ActionGroup(String name) {
		m_name = name;
		m_actionsOrGroups = new ArrayList<Object>();
	}
	
	// ---------- Methods ----------
	
	
	/**
	 * @return the m_actionsOrGroups
	 */
	public List<Object> getActionsOrGroups() {
		return new ArrayList<Object>(m_actionsOrGroups);
	}

	/**
	 * @param m_actionsOrGroups the m_actionsOrGroups to set
	 */
	public void setActionsOrGroups(ArrayList<Object> m_actionsOrGroups) {
		this.m_actionsOrGroups = m_actionsOrGroups;
	}

	/**
	 * @return the m_name
	 */
	public String getName() {
		return m_name;
	}

	/**
	 * @param m_name the m_name to set
	 */
	public void setName(String m_name) {
		this.m_name = m_name;
	}

    public void add(AbstractAction action) {
        m_actionsOrGroups.add(action);
    }
    
    public void add(ActionGroup group) {
        m_actionsOrGroups.add(group);
    }
    

    /**
     * Recursively enable a=groups and actions contained within groups
     */
    public void setEnabled(boolean enabled) {
        for ( Object ob : m_actionsOrGroups) {
            assert ((ob instanceof AbstractAction) || (ob instanceof ActionGroup));
            if ( ob instanceof AbstractAction ) {
                ((AbstractAction)ob).setEnabled(enabled);
            } else {
                ((ActionGroup)ob).setEnabled(enabled);
            }
        }
    }
	
	// ---------- Fields ----------
	
	// The name of the group
	String m_name;
	// The actions and groups in the list 	
	List<Object> m_actionsOrGroups;
	
}
